package cz.muni.fi.pa165.web.validation;

import cz.muni.fi.pa165.api.dto.PickerDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * Validation Class for PickerDTO
 *
 * @author Matej Cimbora
 */
@Service
public class PickerDTOValidator implements Validator {

    @Override
    public boolean supports(Class<?> type) {
        return PickerDTO.class.equals(type);
    }

    @Override
    public void validate(Object o, Errors errors) {
        PickerDTO picker = (PickerDTO) o;
        ValidationUtils.rejectIfEmpty(errors, "firstName", "picker.firstname.empty");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "picker.lastname.empty");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nickName", "picker.nickname.empty");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "picker.password.empty");
    }
}
